<?php
    include_once "common.inc";
    $games = getAllGames($uid);
    include "heading.inc";
?>
<table class="main_tbl">
    <tr>
        <td class="left_col">
        </td>
        <td>
            <?php include "menu.inc"; ?>
        </td>
    </tr>
    <tr>
        <td style="vertical-align: top;">
            <h2>Ваши swot'ы:</h2>
            <script language="JavaScript" type="text/javascript">
                function getsupport (swot,selectedtype) {
                    document.forms[swot].method.value = selectedtype;
                    document.forms[swot].submit();
                    return false;
                }
            </script> 
            <ul class="nav2">
                <?php for ($i = 0; $i < count($games); $i++) { ?>
                <li>
                    <form name="swot<?php echo $games[$i]['gid']; ?>" action="game-stuff.php" method="POST">
                        <input type="hidden" name="method" value=""/>
                        <input type="hidden" name="gid" value="<?php echo $games[$i]['gid']; ?>"/>
                        <a href="#" onclick="return getsupport('swot<?php echo $games[$i]['gid']; ?>', 'choose');">
                            <span class="<?php if ($gid == $games[$i]['gid']) echo "active"; ?>item">
                                <?php echo htmlspecialchars($games[$i]['caption'], ENT_QUOTES, 'UTF-8'); ?>
                            </span>
                        </a>
                        <a href="#" onclick="return getsupport('swot<?php echo $games[$i]['gid']; ?>', 'delete');">Удалить</a>
                    </form>
                </li>
                <?php } ?>
            </ul>
            <form action="game-stuff.php" method="POST" name="new_game_form">
                <input type="hidden" name="method" value="new"/>
                <a href="#" onclick="document.forms['new_game_form'].submit(); return false;">Добавить новый расчет</a>
            </form>
        </td>
        <td>
            <form action="game-stuff.php" method="POST">
                <input type="hidden" name="method" value="change"/>
                <input type="hidden" name="gid" value="<?php echo $gid; ?>"/>
                Название текущего расчета:
                <input type="text" name="caption" value="<?php echo htmlspecialchars($game['caption'], ENT_QUOTES, 'UTF-8'); ?>"/>
                <br/>
                Использовать систему расчета:
                <select name="scheme">
                    <?php $names=array("Жесткая", "Мягкая", "Сомневающаяся"); for ($i = 0; $i < 3; $i++) { ?>
                    <option value="<?php echo $i; ?>" <?php if ($i == $game['scheme']) echo "selected"; ?>><?php echo $names[$i]; ?></option>
                    <?php } ?>
                </select>
                <br/>

<?php
// TODO: add regions and fields support
?>
                Регион:
                <select name="region">
                    <option value="0" selected>Москва</option>
                </select>
                <br/>
                Отрасль:
                <select name="field">
                    <option value="0" selected>IT</option>
                </select>
                <br/>

                <?php if ($authorized) { ?>
                Сделать публичным: 
                <input type="checkbox" name="public" value="1" <?php if ($game['public']) echo "checked"; ?> />
                <br/>
                <?php } else { ?>
                <input type="hidden" name="public" value="0"/>
                <?php } ?>

                Комментарии:<br/>
                <textarea class="comments" name="comments"><?php echo htmlspecialchars($game['comments'], ENT_QUOTES, 'UTF-8'); ?></textarea>
                <br/>
                <input type="submit" value="Сохранить"/>
            </form>
        </td>
    </tr>
</table>
<?php
    include "footer.inc";
?>
